package com.didi.virtualapk.collector.res
/**
 * Represent a resource entry(e.g. drawable, anim, attr, layout...) in android project,
 * the information in this class will be recorded in the arsc file.
 *
 * @author zhengtao
 */
class ResourceEntry {

    /**
     * Type of a resource entry, e.g. drawable
     */
    String resourceType
    /**
     * Name of a resource entry, e.g. abc_btn_check_material is name of a drawable
     */
    String resourceName
    /**
     * Original id value of a resource entry, generated by aapt
     */
    int resourceId

    /**
     * New assigned id value of resource entry, pid is modified
     */
    int newResourceId

    public ResourceEntry(resType, resName, resId) {
        resourceType = resType
        resourceName = resName
        resourceId = resId
    }

    public void setNewResourceId(id) {
        this.newResourceId = id
    }

    /**
     * Generate a new resource id from packageId, typeId, entryId.
     *
     * For example: 0x7f02000e is a id of resource entry
     *
     * @param packageId  7f
     * @param typeId   02
     * @param entryId  0000e
     */
    public void setNewResourceId(packageId, typeId, entryId) {
        newResourceId = packageId << 24 | typeId << 16 | entryId
    }

    /**
     * @return the hexadecimal resource id
     */
    public String getHexResourceId() {
        return "0x${Integer.toHexString(resourceId)}"
    }

    /**
     * @return the hexadecimal new resource id
     */
    public String getHexNewResourceId() {
        return "0x${Integer.toHexString(newResourceId)}"
    }


    boolean equals(o) {
        if (this.is(o)) return true
        if (getClass() != o.class) return false

        ResourceEntry that = (ResourceEntry) o

        if (resourceName != that.resourceName) return false
        if (resourceType != that.resourceType) return false

        return true
    }


    int hashCode() {
        int result
        result = resourceType.hashCode()
        result = 31 * result + resourceName.hashCode()
        return result
    }
}